package com.snake.springboot.authority.service.impl;

import com.snake.springboot.authority.api.model.AuthSystemModel;
import com.snake.springboot.authority.api.service.AuthSystemService;
import com.snake.springboot.authority.dao.mybatis.entity.AuthSystemDO;
import com.snake.springboot.authority.dao.mybatis.mappers.AuthSystemMapper;
import com.snake.springboot.authority.service.assembler.AuthSystemAssembler;
import org.snake.common.utils.ListUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 类 {@code AuthSystemServiceImpl}  <br> .
 * <p>系统信息实现类
 * <p>创建时间：2025/01/07
 *
 * @author Huang.yj
 */
@Service
public class AuthSystemServiceImpl implements AuthSystemService {
    
    private AuthSystemMapper authSystemMapper;

    @Autowired
    public AuthSystemServiceImpl(AuthSystemMapper authSystemMapper) {
        this.authSystemMapper = authSystemMapper;
    }

    @Override
    public AuthSystemModel addSystem(AuthSystemModel model){
        AuthSystemDO entity = AuthSystemAssembler.assembleAuthSystemDO(model);
        authSystemMapper.insert(entity);
        model.setSystemId(entity.getSystemId());
        return model;
    }

    @Override
    public int modifySystem(AuthSystemModel model){
        AuthSystemDO entity = AuthSystemAssembler.assembleAuthSystemDO(model);
        return authSystemMapper.update(entity);
    }

    @Override
    public int removeSystem(String systemId) {
        return authSystemMapper.delete(systemId);
    }

    @Override
    public AuthSystemModel querySingleSystem(String systemId) {
        AuthSystemDO entity = authSystemMapper.findById(systemId);
        AuthSystemModel result = AuthSystemAssembler.assembleAuthSystemModel(entity);
        return result;
    }

    @Override
    public List<AuthSystemModel> querySystemList(AuthSystemModel params){
        AuthSystemDO condition = AuthSystemAssembler.assembleAuthSystemDO(params);
        List<AuthSystemDO> list = authSystemMapper.findByCondition(condition);
        List<AuthSystemModel> result = ListUtils.copy(list, AuthSystemModel.class);
        return result;
    }
}
